package com.rf.richfitwheel.workflow.controller;

import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.common.utils.R;
import com.rf.richfitwheel.common.utils.StringUtils;
import com.rf.richfitwheel.common.utils.TreeUtils;
import com.rf.richfitwheel.workflow.model.WfProcessFolder;
import com.rf.richfitwheel.workflow.model.WfProcessPage;
import com.rf.richfitwheel.workflow.service.WfProcessFolderService;
import com.rf.richfitwheel.workflow.service.WfProcessPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 流程目录表
 *
 * @author zhanglu
 * @email zhanglu2@cnpc.com.cn
 * @date 2021-07-20 09:01:22
 */
@RestController
@RequestMapping("/wfprocesspage")
public class WfProcessPageController {
    @Autowired
    private WfProcessPageService wfProcessPageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = wfProcessPageService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/listByFolderCode")
    public R list(@RequestBody String folderCode) {
        List<WfProcessPage> wfProcessPages = wfProcessPageService.getListByFolderCode(folderCode);

        return R.ok().put("wfProcessPages", wfProcessPages);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        WfProcessPage wfProcessPage = wfProcessPageService.getById(id);

        return R.ok().put("wfProcessPage", wfProcessPage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WfProcessPage wfProcessPage) {
        if (wfProcessPage.getId() == null || "".equals(wfProcessPage.getId())) {
            //新增
            wfProcessPageService.addWfProcessPage(wfProcessPage);
        } else {
            //修改
            wfProcessPageService.updateWfProcessPage(wfProcessPage);
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WfProcessPage wfProcessPage) {
        wfProcessPageService.updateWfProcessPage(wfProcessPage);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/deleteByIds")
    public R delete(@RequestBody String[] ids) {
        wfProcessPageService.deleteByIds(Arrays.asList(ids));

        return R.ok();
    }

    @PostMapping("/deleteById")
    public R deleteById(@RequestBody String id) {
        wfProcessPageService.deleteById(id);
        return R.ok();
    }

}
